home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / UNIXLIB37B / test / c / dirtest < prev    next >
Text File  |  1992-02-24  |  1KB  |  44 lines

  1. /* dirtest.c (c) Copyright 1990 H.Rogers */
  2.  
  3. /* This program tests the directory(3) library routines. */
  4. /* For full information on these, read the appropriate entry
  5.  * in section 3 of the UNIX Programmer's Manual. */
  6.  
  7. #include <stdio.h>            /* standard I/O */
  8. #include <stdlib.h>            /* standard library */
  9. #include <string.h>            /* standard string library */
  10.  
  11. #include "unistd.h"            /* UNIX system calls */
  12. #include "dirent.h"            /* directory handling functions */
  13. #include "sys/stat.h"            /* file status */
  14.  
  15. int main(argc,argv)
  16. int argc;
  17. char **argv;
  18. {
  19. DIR *dirp;                /* directory pointer */
  20. struct direct *d;            /* directory entry structure */
  21. struct stat s[1];            /* file status structure */
  22. static char buf[256];            /* buffer */
  23.  
  24. putchar('\n');
  25.  
  26. while (++argv,--argc)            /* cycle through arguments */
  27.   {
  28.   if (!(dirp = opendir(*argv)))     /* open directory */
  29.     {
  30.     printf("dirtest: could not open directory %s\n\n",*argv);
  31.     continue;
  32.     }
  33.   printf("directory: %s\n\n",*argv);
  34.   while (d = readdir(dirp))        /* read directory entry */
  35.     {
  36.     sprintf(buf,"%s/%s",*argv,d->d_name);
  37.     stat(buf,s);            /* get file status */
  38.     printf("%8o  %s\n",s->st_mode,d->d_name);    /* print file mode & name */
  39.     }
  40.   closedir(dirp);            /* close directory */
  41.   putchar('\n');
  42.   }
  43. }
  44.